package com.entrogy.controller;

import com.alibaba.fastjson.JSON;
import com.entrogy.bean.ParentRecordEntity;
import com.entrogy.bean.PassRecordEntity;
import com.entrogy.service.ParentRecordService;
import com.entrogy.timing.StuRecordService;
import com.entrogy.utils.ApiReturnUtil;
import com.entrogy.utils.HttpUtils;
import com.entrogy.utils.QueueUtils;
import com.entrogy.utils.StrUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.omg.CORBA.UserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.FutureTask;

/**
 * @author xlr
 */
@RestController
@Api(description = "设备流水的操作管理")
@RequestMapping(value = "/studentrecord")
public class StuRecordController {


	@ApiOperation(value = "对通行流水的处理操作")
	@RequestMapping(value = "/check",method = RequestMethod.POST)
	public JSONObject checkRecord(@RequestBody String params){
		com.alibaba.fastjson.JSONObject object= JSON.parseObject(params);
		JSONObject resultMsg = new JSONObject();
		try {
			String name = object.get("person_name").toString();
			String personId = object.get("person_id").toString();
			String deviceId = object.get("device_id").toString();
			int id = 0;
			if (!"null".equals(personId)) {
				id = Integer.parseInt(personId);
			}
			String identtifyTs = object.get("identify_ts").toString();
			double time = 0;
			if (!"null".equals(identtifyTs)) {
				time = Double.parseDouble(identtifyTs);
			}
//			String image = request_body.getString("identify_image");//baseImge64  -----先不存
			String deviceName = object.getString("device_name");
//			String visitorPerIdNumber = request_body.getString("visitor_per_id_number");//访客通过的身份证号码
			Date pass_date = new Date();
			if (time != 0) {
				pass_date.setTime((long) time * 1000);
			}
			PassRecordEntity passRecordEntity = new PassRecordEntity();
			passRecordEntity.setPersonId(id+"");
			passRecordEntity.setPersonName(name);
			passRecordEntity.setDeviceId(deviceId);
			passRecordEntity.setIdentifyTs(pass_date);
			passRecordEntity.setDeviceName(deviceName);
			passRecordEntity.setRecordTime(identtifyTs);
			passRecordEntity.setSchoolCode(Integer.parseInt(deviceName.substring(0,deviceName.indexOf("_")).trim()));
			QueueUtils.offerQueue(passRecordEntity);//入队
			resultMsg.put("status", Integer.valueOf(0));
		} catch (Exception e) {
			e.printStackTrace();
			resultMsg.put("status", Integer.valueOf(0));
			return resultMsg;
		}
		return resultMsg;
	}


}
